/**
 * 轮盘游戏工具
 */	
export class RouUtility
{
	private static Column:string = "Column";
	private static Row:string = "Row";
	private static Small:string = "Small";
	private static Big:string = "Big";
	private static Red:string = "Red";
	private static Black:string = "Black";
	private static Single:string = "Single";
	private static Double:string = "Double";
	/**
	 * 用于判断是否是数字下注区
	 */		
	public static IsNumBetArea(betAreaIndex:number):boolean
	{
		if(betAreaIndex<37&&betAreaIndex>0)return true;
		return false;
	}
	/**
	 * 
	 */		
	public static IsTypeBetArea(betAreaIndex:number):boolean
	{
		if(betAreaIndex>144)return true;
		return false;
	}
	
	
	private static IsSingleBetArea(betAreaIndex:number):boolean
	{
		if(betAreaIndex%2==1)return true;
		return false;
	}
	private static IsRedBetArea(betAreaIndex:number):boolean
	{
		betAreaIndex= (betAreaIndex-1)%18;
		if(betAreaIndex<10)return betAreaIndex%2==0;
		else return betAreaIndex%2==1;
	}
	private static IsSmallBetArea(betAreaIndex:number):boolean
	{
		return betAreaIndex<19;
	}
	private static GetBetAreaColumnNum(betAreaIndex:number):number
	{
		return (betAreaIndex-1)/12;
	}
	private static GetBetAreaRowNum(betAreaIndex:number):number
	{
		return (betAreaIndex-1)%3;
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public static IsMultiBetArea(betAreaType:string):boolean
	{
		var s:string = betAreaType.charAt(0);
		if(s=="S"||s=="W"||s=="E")return false;
		return true;
	}
	
	/**获取下注区类型**/
	public static GetBetAreaType(betAreaType:string):string
	{
		if(betAreaType=="E0")return this.Small;
		if(betAreaType=="E1")return this.Double;
		if(betAreaType=="E2")return this.Red;
		if(betAreaType=="E3")return this.Black;
		if(betAreaType=="E4")return this.Single;
		if(betAreaType=="E5")return this.Big;
		var s:string = betAreaType.charAt(0);
		if(s=="W")
		{
			var c:number = parseInt(betAreaType.charAt(1));
			return c>2?(this.Row+(c-3)):(this.Column+c)
		}
		return betAreaType;
	}
	/**获取到对应下注区的赔率**/
	public static GetBetAreaPay(betAreaType:string):number
	{
		var s:string = betAreaType.charAt(0);
		if(s=="S")return 35;
		if(s=="D")return 17;
		if(s=="T")return 11;
		if(s=="Q")return 8;
		if(s=="H")return 5;
		if(s=="W")return 2;
		return 1;
	}
	/**将下注区id转换成下注区标识**/
	public static TransformBetArea(betAreaIndex:number):string
	{
		if(betAreaIndex<37)return "S"+betAreaIndex;
		if(betAreaIndex<97)return "D"+(betAreaIndex-37);
		if(betAreaIndex<111)return "T"+(betAreaIndex-97);
		if(betAreaIndex<134)return "Q"+(betAreaIndex-111);
		if(betAreaIndex<145)return "H"+(betAreaIndex-134);
		if(betAreaIndex<151)return "W"+(betAreaIndex-145);
		return "E"+(betAreaIndex-151);
	}
	public static GetRedOrBlackType(betAreaIndex:number):string
	{
		return this.IsRedBetArea(betAreaIndex)?this.Red:this.Black;
	}
	public static GetSingleOrDoubleType(betAreaIndex:number):string
	{
		return this.IsSingleBetArea(betAreaIndex)?this.Single:this.Double;
	}
	public static GetSmallOrBigType(betAreaIndex:number):string
	{
		return this.IsSmallBetArea(betAreaIndex)?this.Small:this.Big;
	}
	public static GetColumnType(betAreaIndex:number):string
	{
		return this.Column+this.GetBetAreaColumnNum(betAreaIndex);
	}
	public static GetRowType(betAreaIndex:number):string
	{
		return this.Row+this.GetBetAreaRowNum(betAreaIndex);
	}
	
	
	
	
	public static GetMultiBetArea(betAreaType:number):any[]
	{
		var arr:any[] = [];
		var num:number = betAreaType;
		var count:number = 0;
		var roundNum:number = 0;
		var i:number = 0;
		var round:number;
		var roundIndex:number;
		if(betAreaType>36&&betAreaType<97)// 两个下注区
		{
			num-=37;
			count = 2;
			roundNum = 5;
			round = Math.floor(num/roundNum);
			roundIndex = num%roundNum;
			for(i = 0;i<count;i++)
			{
				var bNum:number = (round-i)*3+roundIndex+1;
				if(roundIndex>2)bNum = (round-i)*3+(roundIndex-2*(1-i))+1;
				if(bNum<0)bNum = 0;
				arr.push(bNum);
			}
		}else if(betAreaType>96&&betAreaType<111)// 三个下注区
		{
			num-=97;
			count = 3;
			roundNum = 3;
			round = num - 2;
			if(round==-1)arr.push(0,3,2);
			else
			{
				for(i = 0;i<count;i++)
				{
					if(round<0)arr.push((round*roundNum+i)+6);
					else arr.push((round*roundNum+i)+1);
				}
			}
		}else  if(betAreaType>110&&betAreaType<134)// 四个下注区
		{
			num-=111;
			count = 4;
			roundNum = 2;
			if(num==0)arr.push(0,3,2,1);
			else
			{
				round = (num-1)/2;
				for(i = 0;i<count;i++)
				{
					roundIndex = i/roundNum;
					arr.push((round+roundIndex)*3+(i%roundNum)+1+(num-1)%2);
				}
			}
		}else if(betAreaType>133&&betAreaType<145)// 六个下注区
		{
			num-=134;
			count = 6;
			roundNum = 3;
			round = num+1;
			for(i = 0;i<count;i++)
			{
				roundIndex = i/roundNum;
				arr.push((round-Math.floor(i/3))*3+i%3+1);
			}
		}
		return arr;
	}
}